<template>
  <el-card class="content-card">
    <template #header>
      <div class="card-header">
        <h3>财务数据</h3>
      </div>
    </template>
    <el-row :gutter="16">
      <el-col :span="8" v-for="(item, index) in financeStats" :key="index">
        <div class="finance-item">
          <div class="finance-icon" :style="{ backgroundColor: item.color }">
            <el-icon :size="20">
              <component :is="getIcon(item.icon)" />
            </el-icon>
          </div>
          <div class="finance-info">
            <div class="finance-name">{{ item.name }}</div>
            <div class="finance-count">{{ item.count }}笔</div>
            <div class="finance-amount">¥{{ item.amount_format }}</div>
          </div>
        </div>
      </el-col>
    </el-row>
  </el-card>
</template>

<script setup lang="ts">
  import { Money, DocumentChecked, User, Calendar } from '@element-plus/icons-vue'

  interface FinanceItem {
    name: string
    count: number
    amount_format: string
    icon: string
    color: string
  }

  interface Props {
    financeStats: FinanceItem[]
  }

  const props = defineProps<Props>()

  // 获取图标组件
  const getIcon = (iconName: string) => {
    const iconMap: Record<string, any> = {
      money: Money,
      'file-done': DocumentChecked,
      user: User,
      calendar: Calendar,
    }
    return iconMap[iconName] || Money
  }
</script>

<style scoped>
  /* 财务统计样式 */
  .content-card {
    height: 100%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: none;
  }

  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
  }

  .finance-item {
    display: flex;
    align-items: center;
    padding: 16px;
    background: #fafafa;
    border-radius: 8px;
    transition: all 0.3s ease;
  }

  .finance-item:hover {
    background: #f0f9ff;
    transform: translateY(-2px);
  }

  .finance-icon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    color: white;
  }

  .finance-info {
    flex: 1;
  }

  .finance-name {
    font-size: 14px;
    color: #333;
    font-weight: 500;
    margin-bottom: 4px;
  }

  .finance-count {
    font-size: 12px;
    color: #666;
    margin-bottom: 2px;
  }

  .finance-amount {
    font-size: 16px;
    font-weight: bold;
    color: #333;
  }

  /* 响应式设计 */
  @media (max-width: 768px) {
    .finance-icon {
      width: 40px;
      height: 40px;
    }

    .finance-name {
      font-size: 13px;
    }

    .finance-count {
      font-size: 11px;
    }

    .finance-amount {
      font-size: 14px;
    }
  }
</style>
